#! /usr/bin/env Rscript
setwd("/Users/matias/Documents/facultad/tesis/goldStandard/estadisticas/")
# Estos valores se calculan con GSvsCantPalabrasCorrelacion del proyecto ocovinu en java.
cantPalabras = c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500)
noHits = c(54.85357142857143,53.725,58.61309523809524,57.43571428571428,58.075,55.03333333333333,56.78690476190476,57.220238095238095,57.041666666666664,57.87619047619048,58.42857142857143,56.885714285714286,56.785714285714285,57.66190476190476,56.53690476190476,57.58571428571429,58.08571428571429,58.10952380952381,57.20952380952381,58.98571428571429,56.90833333333333,58.65833333333333,60.56309523809524,60.73809523809524,59.92261904761905)
yesHits = c(51.387192663788404,53.09400585996331,58.773363028682176,55.799495544176395,58.19381691722117,55.43402368934284,57.24962652622227,58.60809137404882,61.100760334802885,62.95347018751274,63.7193424427467,61.6081613528422,60.71927246395331,60.750160494841346,62.43580966985222,61.23171195511621,62.86134158474584,63.15988937265533,62.28991301331727,62.41743263019859,63.700965403093065,61.793952006717966,62.630788843554804,66.35962406175172,64.72999443212208)
coverage = c(9.6010165336137,17.628927997322364,20.349634104995452,22.932184140935792,24.811649873382386,27.091751831944137,29.043705685655315,30.80164358247895,32.263589852174356,33.68093592512531,35.007308595827496,36.125823144268054,37.266248239697745,37.98075345328193,38.913823124168474,39.82465952182572,40.56216421274456,40.999483881876245,41.44575252752889,42.14145559156782,42.776046400736035,43.382649605438175,43.86095865696122,44.26791517280404,44.75863194491549)
totalHits = c(52.467532467532465,52.72727272727273,58.18181818181818,56.62337662337662,58.441558441558435,55.58441558441558,57.4025974025974,57.92207792207792,58.96103896103896,60.259740259740255,61.038961038961034,58.96103896103896,58.44155844155844,58.96103896103896,59.480519480519476,59.48051948051948,60.51948051948052,60.77922077922078,59.74025974025974,60.77922077922078,60.51948051948052,60.51948051948052,61.81818181818181,63.63636363636363,62.5974025974026)

png(file="ciaoVsCantPalabras.png", width=450, height=400)
par(mar=c(5,4,4,5)+.1)
plot(cantPalabras,noHits,type="o",col="blue", pch=21, ylim=c(50,70), xlab="Cant. Palabras", ylab="% Aciertos")
lines(cantPalabras, yesHits, type="o", pch=22, col="red")
lines(cantPalabras, totalHits, type="o", pch=23, col="violet")

fitYes = nls(yesHits~((c*log(cantPalabras)+b)), start=list(c=3.9651,b=51.321), control=list(maxiter=200))
lines(cantPalabras, predict(fitYes), col="black")
points(cantPalabras, predict(fitYes), col="black", pch="*")
#R^2=0.82412

fitNo = nls(noHits~((c*log(cantPalabras)+b)), start=list(c=1.2668,b=54.65), control=list(maxiter=200))
lines(cantPalabras, predict(fitNo), col="black")
points(cantPalabras, predict(fitNo), col="black", pch="*")
#R^2=0.42689


fitTotal = nls(totalHits~((c*log(cantPalabras)+b)), start=list(c=2.8297,b=52.468), control=list(maxiter=200))
lines(cantPalabras, predict(fitTotal), col="black")
points(cantPalabras, predict(fitTotal), col="black", pch="*")
#R^2=0.80233

par(new=TRUE)
plot(cantPalabras,coverage,,type="o", pch=24, col="green",xaxt="n",yaxt="n",xlab="",ylab="")
axis(4)
mtext("% Cubrimiento",side=4,line=3)
title(main="Aciertos en Ciao.es vs Cant. Palabras", col.main="black", font.main=4)
legend("topleft", c("Negativo","Positivo","Total", "Cubrimiento"), cex=0.8, col=c("blue","red","violet","green"), pch=21:24, lty=1:2)
dev.off()

